package com.magold.game.level;

import java.util.Map;

import com.magold.circuit.ICircuit;
import com.magold.circuit.ICircuitPath;
import com.magold.circuit.module.CircuitModule;

public class CircuitModuleProxy implements CircuitModule {
	private int mID;
	private Map<Integer, ?> mMap;
	private CircuitModule mModule;
	
	public CircuitModuleProxy(int pID, Map<Integer, ?> pMap) {
		mID = pID;
		mMap = pMap;
	}
	
	public CircuitModule getModule() {
		if (mModule == null) {
			mModule = (CircuitModule) mMap.get(mID);
			mModule.setID(mID);
		}
		
		return mModule;
	}
	
	@Override
	public boolean isConnected() {
		return getModule().isConnected();
	}

	@Override
	public void onCurrentBegin() {
		getModule().onCurrentBegin();
	}

	@Override
	public void onCurrentEnd() {
		getModule().onCurrentEnd();
	}

	@Override
	public void onPathJoined(ICircuit pCircuit, ICircuitPath pPath) {
		getModule().onPathJoined(pCircuit, pPath);
	}

	@Override
	public void setID(int pID) {
		getModule().setID(pID);
	}

	@Override
	public int getID() {
		return mID;
	}

	@Override
	public float[] getWireInPosition() {
		return getModule().getWireInPosition();
	}

	@Override
	public float[] getWireOutPosition() {
		return getModule().getWireOutPosition();
	}

}
